package com.easy.cloud.web.service.upms.biz.domain;

import com.easy.cloud.web.component.mysql.annotation.EnableLogic;
import com.easy.cloud.web.component.mysql.annotation.EnableTenant;
import com.easy.cloud.web.component.mysql.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.List;

/**
 * Role 持久类
 *
 * @author Fast Java
 * @date 2023-08-03 14:32:52
 */
@Entity
@Data
@SuperBuilder
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@DynamicInsert
@DynamicUpdate
@EnableTenant
@EnableLogic
@Table(name = "db_role")
public class RoleDO extends BaseEntity {

    /**
     * 角色编码
     */
    @Column(columnDefinition = "VARCHAR(64) NOT NULL COMMENT '角色编码'")
    private String code;
    /**
     * 角色名称
     */
    @Column(columnDefinition = "VARCHAR(64) NOT NULL COMMENT '角色名称'")
    private String name;
    /**
     * 描述
     */
    @Column(columnDefinition = "VARCHAR(255) NOT NULL DEFAULT '' COMMENT '描述'")
    private String remark;
    /**
     * 排序字段，数值越小越排靠前
     */
    @Column(columnDefinition = "INT NOT NULL DEFAULT '0' COMMENT '排序'")
    private Integer sort;

    /**
     * 用户角色
     */
    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinTable(name = "db_role_menu",
            joinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "menu_id", referencedColumnName = "id"),
            foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private List<MenuDO> menus;
}